package com.rui.study.algorithm.P_最长回文串;

import java.util.HashSet;
import java.util.Set;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-01-11 09:34
 **/
public class Solution {
    public int longestPalindrome(String s) {
        int n = s.length();
        int maxLen = 0;
        Set<Character> set = new HashSet(n);
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (!set.add(c)) {
                maxLen += 2;
                set.remove(c);
            }
        }
        if (set.size() > 0) {
            maxLen += 1;
        }
        return maxLen;
    }
}
